<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">

      <div>
        <!-- 搜索 -->
        <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column align="center" prop="bisQyZt" label="签约状态" width="130">
          <template slot-scope="scope">
            {{ dict.label.qygl[scope.row.bisQyZt] }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="bisZhsqSnryXm" label="姓名" />
        <el-table-column align="center" prop="bisZhsqSnryXb" label="性别" />
        <el-table-column align="center" prop="bisZhsqSnrySfz" label="身份证" width="150" />
        <el-table-column align="center" prop="bisGsglIszf" label="是否作废" width="130">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bisGsglIszf === '1'" effect="plain" type="">
              正常
            </el-tag>
            <el-tag v-else-if="scope.row.bisGsglIszf === '0'" effect="plain" type="warning">
              作废
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="bisZhsqNl" label="年龄" />
        <el-table-column align="center" prop="bisZhsqSndj" label="失能等级" />
        <el-table-column align="center" prop="bisZhsqAdl" label="评分" />
        <el-table-column align="center" prop="bisZhsqLxdh" label="联系电话" width="100" />
        <el-table-column align="center" prop="bisZhsqJhrxm" label="监护人姓名" />
        <el-table-column align="center" prop="bisZhsqJhrdh" label="监护人电话" width="130" />
        <el-table-column align="center" prop="bisZhsqHldz" label="护理地址" width="130" />
        <el-table-column align="center" prop="sqsj" label="申请时间" width="140" />
        <el-table-column align="center" prop="bisZhsqGx" label="关系">
          <template slot-scope="scope">
            {{ dict.label.yjsgx[scope.row.bisZhsqGx] }}
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleClick(scope.row)">取消</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudQy from '@/api/business/qy'
import CRUD, { presenter, header, form } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisZhsqId: null, bisZhsqSnryId: null, bisZhsqSnryXm: null, bisZhsqSnryXb: null, bisZhsqSnrySfz: null, bisSnryYbssqx: null, bisZhsqDykkrq: null, bisZhsqDyjsrq: null, bisZhsqXsdyq: null, bisZhsqAdl: null, bisZhsqZt: null }
export default {
  name: 'Zhsq',
  components: { pagination, rrOperation },
  mixins: [presenter(), header(), form(defaultForm)],
  dicts: ['xb', 'yjsgx', 'qygl', 'zhzt'],
  cruds() {
    return CRUD({ title: '居家照护申请', url: 'api/qy/queryAllQyList', idField: 'bisZhsqId', sort: 'lrsj,desc' })
  },
  data() {
    return {
      approveDialog: false,
      selectedZhids: [],
      bisGsglId: '',
      permission: {
        add: ['admin', 'zhsq:add'],
        edit: ['admin', 'zhsq:edit'],
        del: ['admin', 'zhsq:del']
      },
      rules: {
        bisZhsqSnryXm: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        bisZhsqSnryXb: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        bisZhsqSnrySfz: [
          { required: true, message: '身份证不能为空', trigger: 'blur' }
        ],
        bisSnryYbssqx: [
          { required: true, message: '医保所属区县不能为空', trigger: 'blur' }
        ],
        bisZhsqDykkrq: [
          { required: true, message: '待遇开始日期不能为空', trigger: 'blur' }
        ],
        bisZhsqDyjsrq: [
          { required: true, message: '待遇结束日期不能为空', trigger: 'blur' }
        ],
        bisZhsqXsdyq: [
          { required: true, message: '享受待遇期不能为空', trigger: 'blur' }
        ],
        bisZhsqAdl: [
          { required: true, message: 'ADL量表评分不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    handleClick(rowOjb) {
      console.log(rowOjb)
      if (rowOjb.bisQyZt === 'qygl03') {
        this.$notify({
          title: '此照护申请已签约，无法操作',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.$confirm('你确定取消吗?<br>执行此操作，公众号用户端，会重新选择护理机构', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        dangerouslyUseHTMLString: true,
        type: 'warning'
      }).then(() => {
        crudQy.updateQyzfzt(rowOjb.bisQyId)
          .then(res => {
            this.$notify({
              title: '完成取消',
              type: 'success',
              duration: 2500
            })
            this.crud.toQuery()
          })
          .catch(err => {
            console.log(err)
          })
      })
    }
  }
}
</script>

<style scoped>

</style>
